﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ASPNETMVCApplication.ActionServiceReference;
using ASPNETMVCApplication.Areas.Shop.Models;
namespace ASPNETMVCApplication.Areas.Supp.Models
{
    /// <summary>
    /// Static class that maps Product and Cart Model objects to 
    /// Data Transfer Objects (DTOs) and vice versa.
    /// This class contains extension methods only.
    /// </summary>
    public static class Mapper
    {
        
        public static SupplierModel ToModel(this Supplier supplier)
        {            
            return new SupplierModel
            {
                SupplierId = supplier.SupplierId,
                CompanyName = supplier.CompanyName,
                LogoUrl = supplier.LogoUrl,
                Email = supplier.Email,
                CompanyPhone = supplier.CompanyPhone,
                Mobilephone = supplier.Mobilephone,
                YahooId = supplier.YahooId,
                SkypeId = supplier.SkypeId,
                GoogleId = supplier.GoogleId,
                FacebookId = supplier.FacebookId,
                UserName = supplier.UserName,
                Password = supplier.Password,
                Address = supplier.Address,
                Description = supplier.Description,
                Status = supplier.Status,
                Version = supplier.Version 
            };
        }
        
        public static Supplier FromModel(this SupplierModel supplierModel)
        {
            return new Supplier
            {
                SupplierId = supplierModel.SupplierId,
                CompanyName = supplierModel.CompanyName,
                LogoUrl = supplierModel.LogoUrl,
                Email = supplierModel.Email,
                CompanyPhone = supplierModel.CompanyPhone,
                Mobilephone = supplierModel.Mobilephone,
                YahooId = supplierModel.YahooId,
                SkypeId = supplierModel.SkypeId,
                GoogleId = supplierModel.GoogleId,
                FacebookId = supplierModel.FacebookId,
                UserName = supplierModel.UserName,
                Password = supplierModel.Password,
                Address = supplierModel.Address,
                Description = supplierModel.Description,
                Status = supplierModel.Status,
                Version = supplierModel.Version
            };
        }
        
        public static List<SupplierModel> ToModel(this List<Supplier> suppliers)
        {
            var models = new List<SupplierModel>();
            if (suppliers != null && suppliers.Count > 0)
                suppliers.ForEach(s => models.Add(s.ToModel()));

            return models;
        }

        public static TrafficModel ToModel(this Traffic traffic)
        {
            return new TrafficModel
            {
                TrafficId = traffic.TrafficId,
                SupplierId = traffic.SupplierId,
                ServiceId = traffic.ServiceId,
                TrafficTypeId = traffic.TrafficTypeId,
                DriverId = traffic.DriverId,
                SubDriverId1 = traffic.SubDriverId1,
                SubDriverId2 = traffic.SubDriverId2,
                Layer = traffic.Layer,
                L1RowNumber = traffic.L1RowNumber,
                L1NCPR = traffic.L1NCPR,
                L2RowNumber = traffic.L2RowNumber,
                L2NCPR = traffic.L2NCPR,
                Description = traffic.Description,
                Picture = traffic.Picture,
                Version = traffic.Version,
                Status = traffic.Status,
            };
        }

        public static Traffic FromModel(this TrafficModel trafficModel)
        {
            return new Traffic
            {
                TrafficId = trafficModel.TrafficId,
                TrafficName=trafficModel.TrafficName,
                SupplierId = trafficModel.SupplierId,
                ServiceId = trafficModel.ServiceId,
                TrafficTypeId = trafficModel.TrafficTypeId,
                DriverId = trafficModel.DriverId,
                SubDriverId1 = trafficModel.SubDriverId1,
                SubDriverId2 = trafficModel.SubDriverId2,
                Layer = trafficModel.Layer,
                L1RowNumber = trafficModel.L1RowNumber,
                L1NCPR = trafficModel.L1NCPR,
                L2RowNumber = trafficModel.L2RowNumber,
                L2NCPR = trafficModel.L2NCPR,
                Description = trafficModel.Description,
                Picture = trafficModel.Picture,
                Version = trafficModel.Version,
                Status = trafficModel.Status,
                
            };
        }

        public static List<TrafficModel> ToModel(this List<Traffic> traffics)
        {
            var models = new List<TrafficModel>();
            if (traffics != null && traffics.Count > 0)
                traffics.ForEach(t => models.Add(t.ToModel()));
            return models;
        }

        public static EmployeeModel ToModel(this Employee employee)
        {
            return new EmployeeModel
            {
                EmployeeId = employee.EmployeeId,
                SupplierId = employee.SupplierId,
                Name = employee.Name,
                Picture = employee.Picture,
                Sex = employee.Sex,
                YahooId = employee.YahooId,
                SkypeId = employee.SkypeId,
                GoogleId = employee.GoogleId,
                FacebookId = employee.FacebookId,
                Telephone = employee.Telephone,
                MobilePhone = employee.MobilePhone,
                Version = employee.Version,
                Status = employee.Status,
            };
        }

        public static Employee FromModel(this EmployeeModel employeeModel)
        {
            return new Employee
            {
                EmployeeId = employeeModel.EmployeeId,
                SupplierId = employeeModel.SupplierId,
                Name = employeeModel.Name,
                Picture = employeeModel.Picture,
                Sex = employeeModel.Sex,
                YahooId = employeeModel.YahooId,
                SkypeId = employeeModel.SkypeId,
                GoogleId = employeeModel.GoogleId,
                FacebookId = employeeModel.FacebookId,
                Telephone = employeeModel.Telephone,
                MobilePhone = employeeModel.MobilePhone,
                Version = employeeModel.Version,
                Status = employeeModel.Status,

            };
        }

        public static List<EmployeeModel> ToModel(this List<Employee> employees)
        {
            var models = new List<EmployeeModel>();
            if (employees != null && employees.Count > 0)
                employees.ForEach(e=> models.Add(e.ToModel()));
            return models;
        }

        public static Category FromModel(this CategoryModel categoryModel)
        {
            return new Category
            {
                CategoryId = categoryModel.CategoryId,
                TrafficId = categoryModel.TrafficID,
                Date = categoryModel.Date,
                FirstPoint = categoryModel.FirstPoint,
                LastPoint = categoryModel.LastPoint,
                StartTime = categoryModel.StartTime,
                EndTime = categoryModel.EndTime,
                Description = categoryModel.Description,
                SupplierId = categoryModel.SupplierID,
                Status = categoryModel.Status,               
            };
        }
    }
}